package com.qfedu.edu.exceptionbusinesshandlerservice.controller;


import com.baomidou.mybatisplus.core.metadata.IPage;
import com.qfedu.edu.exceptionbusinesshandlerservice.service.ExceptionService;
import com.qfedu.edu.po.Exception;
import com.qfedu.edu.result.R;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

import java.io.UnsupportedEncodingException;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author xiaobobo
 * @since 2024-11-18
 */
@RestController
@RequestMapping("/exceptionbusinesshandlerservice/exception")
public class ExceptionController {


    @Autowired
    private ExceptionService exceptionService;

    /**
     * 所有的异常业务
     * 这个异常业务是要在管理端实现手动重试的
     * 手动重试失败的话 那么就人为介入进行代码的检查...目标是数据的最终一致
     * @param currentPage
     * @param pageSize
     * @return
     */
    @GetMapping("listByPage")
    public R listByPage(Integer currentPage,Integer pageSize){
        IPage<Exception> exceptionIPage=exceptionService.listByPage(currentPage,pageSize);
        return R.ok().data("exceptionList",exceptionIPage.getRecords()).data("total",exceptionIPage.getTotal());
    }

    /**
     * 重试咋们的业务(发送重试到目标队列)
     * @param exceptionId
     * @return
     */
    public R retryBusiness(Integer exceptionId) throws UnsupportedEncodingException {
        exceptionService.retryBusiness(exceptionId);
        return R.ok();
    }


}

